﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using XCore.Redis;

namespace SaaS.Tool
{
    public enum UserStatus : byte
    {
        None,
        Delete,
    }
    public struct UserModel_1
    {
        public int UserID;
        public string UserName;
        public bool IsDefault;
        public UserStatus Status;
        public DateTime CreateAt;

        public static implicit operator UserModel_1(HashEntry[] hash)
        {
            UserModel_1 model = new UserModel_1();
            foreach (HashEntry item in hash)
            {
                switch (item.Name)
                {
                    case "UserID":
                        model.UserID = item.Value.GetRedisValue<int>();
                        break;
                    case "UserName":
                        model.UserName = item.Value.GetRedisValue<string>();
                        break;
                    case "IsDefault":
                        model.IsDefault = item.Value.GetRedisValue<bool>();
                        break;
                    case "Status":
                        model.Status = item.Value.GetRedisValue<UserStatus>();
                        break;
                    case "CreateAt":
                        model.CreateAt = item.Value.GetRedisValue<DateTime>();
                        break;
                    default:
                        break;
                }
            }
            return model;
        }

        public static implicit operator HashEntry[](UserModel_1 model)
        {
            return new[]
            {
                new HashEntry("UserID",model.UserID.ToRedisValue()),
                new HashEntry("UserName",model.UserID.ToRedisValue()),
                new HashEntry("IsDefault",model.UserID.ToRedisValue()),
                new HashEntry("Status",model.UserID.ToRedisValue()),
                new HashEntry("CreateAt",model.UserID.ToRedisValue()),
            };
        }
    }
    public struct UserModel_2
    {
        public int UserID;
        public string UserName;
        public bool IsDefault;
        public UserStatus Status;
        public DateTime CreateAt;

        public static implicit operator UserModel_2(HashEntry[] hash)
        {
            return hash.GetReidsHashValue<UserModel_2>();
        }
        public static implicit operator HashEntry[](UserModel_2 model)
        {
            return model.GetRedisHashEntry();
        }
    }
}
